package com.edu.lxshpc.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Collection;

import com.fasterxml.jackson.annotation.JsonValue;
import org.springframework.security.core.userdetails.UserDetails;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.SchemaProperty;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;

/**
 * 
 * @TableName user
 */
@TableName(value ="user")
@Data
@Schema(name = "user",description = "用户实体类")
public class User implements Serializable,UserDetails {
    /**
     * 主键
     */
    @TableId(type = IdType.ASSIGN_ID)
    @SchemaProperty(name="用户id")
    private Long id;

    /**
     * 用户昵称
     */
    @SchemaProperty(name = "用户昵称")
    private String nickname;

    /**
     * 用户名
     */
    @Schema(name = "用户名")
    private String username;

    /**
     * 密码
     */
    @Schema(name = "用户密码")
    private String password;

    /**
     * 0可用1已注销2锁定
     */
    @Schema(name = "用户账号状态")
    private int status;

    /**
     * 用户头像url
     */
    @Schema(name = "用户头像url")
    private String avatar;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;
    /**
     * token信息
     */
    @TableField(exist = false)
    private String token;
    /**
     * 用户权限信息
     */
    @TableField(exist = false)
    private Collection<GrantedAuthority> authorities;
    /**
     * 用户权限信息
     */
    @TableField(exist = false)
    private String authority;
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        User user = (User) o;

        if (status != user.status) {
            return false;
        }
        if (id != null ? !id.equals(user.id) : user.id != null) {
            return false;
        }
        if (nickname != null ? !nickname.equals(user.nickname) : user.nickname != null) {
            return false;
        }
        if (username != null ? !username.equals(user.username) : user.username != null) {
            return false;
        }
        if (password != null ? !password.equals(user.password) : user.password != null) {
            return false;
        }
        if (avatar != null ? !avatar.equals(user.avatar) : user.avatar != null) {
            return false;
        }
        return token != null ? token.equals(user.token) : user.token == null;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (nickname != null ? nickname.hashCode() : 0);
        result = 31 * result + (username != null ? username.hashCode() : 0);
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + status;
        result = 31 * result + (avatar != null ? avatar.hashCode() : 0);
        result = 31 * result + (token != null ? token.hashCode() : 0);
        return result;
    }

    @Override
    public boolean isAccountNonExpired() {
        return getStatus() != 1;
    }

    @Override
    public boolean isAccountNonLocked() {
        return getStatus() != 2;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return getStatus() == 0;
    }
}